/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.rakev.matcher.factory;

import java.util.Collection;
import ru.rakev.matcher.Matcher;

/**
 *
 * @author Rakev
 */
public class MatcherAdapterFactory {

    private static MatcherAdapterFactory instance = new MatcherAdapterFactory();

    public static MatcherAdapterFactory create() {
        return instance;
    }

    protected MatcherAdapterFactory() {
    }

    public <T, C extends Collection<? extends T>> Matcher<C> anyFromCollection(final Matcher<T> matcher) {
        return new Matcher<C>() {
            @Override
            public boolean matches(C items) {
                for (T item : items) {
                    if (matcher.matches(item)) {
                        return true;
                    }
                }
                return false;
            }
        };
    }
}
